package hospital.example;

import java.util.*;

public class GroupCard {
    public static void main(String[] args) {
        GroupCard group1 = new GroupCard();
        group1.addUser(new String[]{"张三", "李四", "王五"});
        group1.printCard();
    }
    private int[] sizes = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
    private String[] colors = {"♥", "◇", "♣", "♠"};
    private String[] nums = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
    private List<Card> cards = new ArrayList<>();
    private List<Person> persons = new ArrayList<>();
    public GroupCard(){
        for(int i = 0;i < 52;i++){
            cards.add(new Card(sizes[i % 13], colors[i / 13], nums[i % 13]));
        }
        cards.add(new Card(14, "black", "小王"));
        cards.add(new Card(15, "red", "大王"));
        System.out.println("卡牌初始化成功，现在共有" + cards.size() + "张牌");
    }
    public void addUser(String[] names){
        for(String i : names){
            persons.add(new Person(i));
        }
        System.out.println("用户添加成功");
    }
    public void printCard(){
        Collections.shuffle(cards);
        for(int i = 0;i < 51;i++){
            persons.get(i % 3).add(cards.get(i));
        }
        Random rm = new Random();
        int dizhu = rm.nextInt(10);
        System.out.println("地主是" + persons.get(dizhu % 3).getName());
        List<Card> dizhuCard = cards.subList(cards.size() - 3, cards.size());
        persons.get(dizhu % 3).addAll(dizhuCard);
        System.out.println("牌局分发完成");
        for(Person person:persons){
            person.cardShow();
        }
    }

}
